<?php

namespace App\Controllers;

use App\Services\MasterLogService;
use App\Services\SearchTimeLimitService;
use common\enum\MasterLogEnum;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;


class LogController extends BaseController
{

    // 获取厅主后台操作日志列表
    public function getAdminLogList(Request $request)
    {
        $params = $request->input();
        //搜索时间限制
        if (!empty($params['date_begin']) && !empty($params['date_end'])) {
            SearchTimeLimitService::timeLimit($params['date_begin'],$params['date_end'],SearchTimeLimitService::THREE_MONTH);
        }
        return MasterLogService::getAdminLogList($params);
    }
    // 获取总后台操作日志列表
    public function getMasterLogList(Request $request)
    {
        $params = $request->input();
        //搜索时间限制
        if (!empty($params['date_begin']) && !empty($params['date_end'])) {
            SearchTimeLimitService::timeLimit($params['date_begin'],$params['date_end'],SearchTimeLimitService::THREE_MONTH);
        }
        return MasterLogService::getMasterLogList($params);
    }

    // 获取会员操作日志列表
    public function getUserLogList(Request $request)
    {
        $params = $request->input();
        //搜索时间限制
        if (!empty($params['date_begin']) && !empty($params['date_end'])) {
            SearchTimeLimitService::timeLimit($params['date_begin'],$params['date_end'],SearchTimeLimitService::THREE_MONTH);
        }
        return MasterLogService::getUserLogList($params);
    }

    // 获取代理操作日志列表
    public function getAgentLogList(Request $request)
    {
        $params = $request->input();
        //搜索时间限制
        if (!empty($params['date_begin']) && !empty($params['date_end'])) {
            SearchTimeLimitService::timeLimit($params['date_begin'],$params['date_end'],SearchTimeLimitService::THREE_MONTH);
        }
        return MasterLogService::getAgentLogList($params);
    }

    // 获取 操作类型/模块名称/子模块
    public function getTypeList(Request $request)
    {
        $params = $request->input();
        return MasterLogService::getTypeList($params);
    }

    /**
     * 三级联动
     * @param Request $request
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function threeLevelLinkList(Request $request){
        $this->validate($request, [
            'type' => ['required', Rule::in(MasterLogEnum::ADMIN, MasterLogEnum::MASTER)],
        ]);
        $type = $request->input('type');
        return MasterLogService::threeLevelLinkList($type);
    }
    /**
     * 下拉菜单列表
     * @param Request $request
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function searchCriteria(Request $request)
    {
        $this->validate($request, [
            'type' => ['required', Rule::in(MasterLogEnum::ADMIN, MasterLogEnum::MASTER,MasterLogEnum::USER, MasterLogEnum::AGENT)],
        ]);
        $type = $request->input('type');
        return MasterLogService::distribute($type);
    }


    /**
     * 总后台日志详情
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function getMasterLoginfo(Request $request)
    {
        $this->validate($request, [
            'master_id' => 'required',
            'item_id' => 'required',
        ]);
        $masterId = $request->input('master_id');
        $itemId = $request->input('item_id');
        return MasterLogService::getMasterLoginfo($masterId,$itemId);
    }

    public function logDetail(Request $request){
        $this->validate($request, [
            'admin_id' => 'required',
            'item_id' => 'required',
        ]);
        $adminId = $request->input('admin_id');
        $itemId = $request->input('item_id');
        return MasterLogService::logDetail($adminId,$itemId);
    }


}
